home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Games / Hexagonal CA / HexCA.h / AppMacros.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-25  |  5.6 KB  |  84 lines  |  [TEXT/CWIE]

  1. /* Macros.h    A collection of useful macros by Alexander M Kasprzyk and Aaron Davidson.
  2.             If you encounter any problems with these macros, please send an eMail to:
  3.                 alex@kasprzyk.demon.co.uk
  4. */
  5.  
  6. #ifndef _AppMacros_
  7. #define _AppMacros_
  8.  
  9. #define _StrictFunctions_                        0        // 1 = Strict Functions; 0 = Macros
  10.  
  11. #if _StrictFunctions_
  12.     #define    MGetWRefCon( win )            GetWRefCon( win )
  13.     #define    MSetWRefCon( win, data )        SetWRefCon( win, data )
  14.     #define    MGetGWorldPixMap( wld )        GetGWorldPixMap( wld )
  15. #else
  16.     #define    MGetWRefCon( win )            ((WindowPeek)(win))->refCon
  17.     #define    MSetWRefCon( win, data )        ((WindowPeek)(win))->refCon = data
  18.     #define    MGetGWorldPixMap( wld )        (wld)->portPixMap
  19. #endif
  20.  
  21. #define    MAbs( num )                        ((num) < 0 ? -(num) : (num))
  22. #define    MAddPt( adPt, dstPt )                (dstPt).h += (adPt).h; (dstPt).v += (adPt).v        
  23. #define    MBitAnd( v1, v2 )                    ((v1) & (v2))    
  24. #define    MBitClear( val, bitNum )                (val) &= ~(0x1 << (bitNum))        
  25. #define    MBitNot( val )                        ~(val)
  26. #define    MBitOr( v1, v2 )                    ((v1) | (v2))    
  27. #define    MBitSet( val, bitNum )                (val) |= 0x1 << (bitNum)        
  28. #define    MBitShift( val, count )                (count) < 0 ? (val) >> (-(count)) : (val) << (count)        
  29. #define    MBitTst( val, bitNum )                (((val) >> (bitNum)) & 0x1)        
  30. #define    MBitXor( v1, v2 )                    (v1) ^ (v2)    
  31. #define    MCountDITL( dlog )                    **((short **)((DialogPeek)dlog)->items) + 1
  32. #define    MCTSeedSmash( wrld )                (*((*MGetGWorldPixMap((wrld)))->pmTable))->ctSeed = (*((*((*(GetGDevice()))->gdPMap))->pmTable))->ctSeed        
  33. #define    MEmptyRect( rct )                    ((rct).bottom <= (rct).top || (rct).right <= (rct).left)    
  34. #define    MEqualRect( r1, r2 )                    ((r1).left == (r2).left && (r1).right == (r2).right && (r1).top == (r2).top && (r1).bottom == (r2).bottom)    
  35. #define    MGetEntryColor( plt, entry, rgb )        rgb = (**(plt)).pmInfo[entry].ciRGB                
  36. #define    MGetEntryUsage( plt, entry, usg, tol )    usg = (**(plt)).pmInfo[entry].ciUsage; tol = (**(plt)).pmInfo[entry].ciTolerance                    
  37. #define    MGetPt( pt, dh, dv )                    dh = (pt).h; dv = (pt).v    
  38. #define    MGetRect( rct, t, l, b, r )                t = (rct).top; l = (rct).left; b = (rct).bottom; r = (rct).right        
  39. #define    MGetRectHeight( r )                    ((r).bottom - (r).top)    
  40. #define    MGetRectWidth( r )                    ((r).right - (r).left)
  41. #define    MGetRowBytes( wrld )                (**MGetGWorldPixMap( (wrld) )).rowBytes & 0x3FFF
  42. #define    MGetWKind( win )                    ((WindowPeek)(win))->windowKind    
  43. #define    MGetWTitleHandle( win )                ((WindowPeek)(win))->titleHandle        
  44. #define    MHex2Perc( hx )                    (hx) / 0x028F    
  45. #define    MHiWord( val )                        (val) >> 16
  46. #define    MHiWordChar( val )                    (val) >> 4    
  47. #define    MHiWordShort( val )                    (val) >> 8    
  48. #define    MInsetRect( rct, dh, dv)                (rct).left += dh; (rct).top += dv; (rct).right -= dh; (rct).bottom -= dv
  49. #define    MInvertBoolean( b )                    (b) = !(b)
  50. #define    MIsWVisible( win )                    ((WindowPeek)(win))->visible
  51. #define    MLoWord( val )                        (val) & 0x0000FFFF
  52. #define    MLoWordChar( val )                    (val) & 0x0F    
  53. #define    MLoWordShort( val )                    (val) & 0x00FF    
  54. #define    MMapPt( pt, srcRct, dstRct )            (pt).h = ((pt).h - (srcRct).left + 1) * (((dstRct).right - (dstRct).left + 1) / ((srcRct).right = (srcRct).left + 1)) + (dstRct).left + 1; (pt).v = ((pt).v - (srcRct).top + 1) * (((dstRct).bottom - (dstRct).top + 1) / ((srcRct).bottom = (srcRct).top + 1))            
  55. #define    MMaxNum( num1, num2 )                ((num1) < (num2) ? (num2) : (num1))    
  56. #define    MMidPoint( pt1, pt2, mid )            (mid).h = (pt1).h + ((pt2).h - (pt1).h)/2; (mid).v = (pt1).v + ((pt2).v - (pt1).v)/2
  57. #define    MMinNum( num1, num2 )                ((num1) > (num2) ? (num2) : (num1))    
  58. #define    MOffsetRect( rct, dh, dv )                (rct).left += dh; (rct).right += dh; (rct).top += dv; (rct).bottom += dv        
  59. #define    MPerc2Hex( pct )                    (unsigned short)((0xFFFF * (unsigned long)(pct)) / 0x64)
  60. #define    MPercentage( value, total )            ((value) / (total)) * 100            
  61. #define    MPointInRect( x, y, rct )                ((x > (rct).left) && (x < (rct).right) && (y > (rct).top) && (y < (rct).bottom))    
  62. #define    MPtInRect( pt, r )                    (((pt).h >= (r).left) && ((pt).h <= (r).right) && ((pt).v >= (r).top) && ((pt).v <= (r).bottom))
  63. #define    MRandomRange( range )                MAbs( ((long)Random() * (range) ) / 32768) + 1    
  64. #define    MRandomPerc( pct )                    (Random() <= MPerc2Hex( pct ))    
  65. #define    MScalePt( pt, srcRct, dstRct )            (pt).h *= (((dstRct).right - (dstRct).left) / ((srcRct).right - (srcRct).left)); (pt).v *= (((dstRct).bottom - (dstRct).top) / ((srcRct).bottom - (srcRct).top))            
  66. #define    MSetPt( pt, dh, dv )                    (pt).h = dh; (pt).v = dv    
  67. #define    MSetRect( rct, l, t, r, b )                (rct).left = l; (rct).top = t; (rct).right = r; (rct).bottom = b        
  68. #define    MSetRGBColor( col, r, g, b )            (col).red = r; (col).green = g; (col).blue = b            
  69. #define    MStringCopy( src, dst )                BlockMove( src, (dst), src[0] + 1 )        
  70. #define    MStringToOSType( str, ty )            ty = (OSType)(str[1])            
  71. #define    MSubPt( sbPt, dstPt )                (dstPt).h -= (sbPt).h; (dstPt).v -= (sbPt).v        
  72. #define    MTESelectionLength( teHdl )            (**(teHdl)).selEnd - (**(teHdl)).selStart    
  73.  
  74. // the following are a set of macros to set an RGBColor to the same values as the standard eight QD colour constants
  75. #define    MGetBlackColor( col )                (col).red = (col).green = (col).blue = 0
  76. #define    MGetYellowColor( col )                (col).red = 0xFC00; (col).green = 0xF37D; (col).blue = 0x052F
  77. #define    MGetMagentaColor( col )                (col).red = 0xF2D7; (col).green = 0x0856; (col).blue = 0x84EC
  78. #define    MGetRedColor( col )                    (col).red = 0xDD6B; (col).green = 0x08C2; (col).blue = 0x06A2
  79. #define    MGetCyanColor( col )                (col).red = 0x0241; (col).green = 0xAB54; (col).blue = 0xEAFF
  80. #define    MGetGreenColor( col )                (col).red = 0; (col).green = 0x64AF; (col).blue = 0x11B0
  81. #define    MGetBlueColor( col )                    (col).red = (col).green = 0; (col).blue = 0xD400
  82. #define    MGetWhiteColor( col )                (col).red = (col).green = (col).blue = 0xFFFF
  83.  
  84. #endif